<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class turnnumric {

        /**
         * 10进制转2、8、16、36、62进制
         *
         * @param int $shu 要转换的数字
         * @param int $jinzhi 要转换的进制(2,8,16,36,62)
         * @param int $w 长度
         * @return string
         */
        function turnnumric_0($shu,$jinzhi,$w)
    {
         $zifu = "";
         while ($shu!=0)
         {
                $linshi = $shu%$jinzhi;
                switch ($jinzhi)
                {
                     case 2:
                         $zifu = decbin($shu);
                         return $zifu;
                     case 8:
                         $zifu= decoct($shu);
                         return $zifu;
                     case 16:
                         $zifu = dechex($shu);
                         return $zifu;
                     case 36:
                         if ($linshi>=10)
                          {
                          $zifu.= chr(($linshi+55));
                          }else{
                                $zifu.= $linshi;}
                         break;
                      case 62:
                          if (($linshi>=10) && ($linshi<36)) {$zifu.= chr($linshi+55);break;}
                          if (($linshi>=36) && ($linshi<62)) {$zifu.= chr($linshi+61);break;}
                          $zifu.= $linshi;break;
                           default:
                           $zifu.= $linshi;
                           break;
                                }
                $shu = intval($shu/$jinzhi);
                        }
         for ($i=strlen($zifu);$i<$w;$i++)
         $zifu.="0";
        return strrev($zifu);
    }
         

    /**
     * 将2、8、16、36、62进制转10进制
     *
     * @param unknown_type $zifu 其它进制数
     * @param int $jinzhi 指定的进制
     * @param int $w 长度
     * @return 十进制数
     */
        function turnnumric_1($zifu,$jinzhi)
        {
                $shu=0;
        for ($i=0;$i<=strlen($zifu)-1;$i++)
        {
          $linshi = substr($zifu,$i,1);
          switch ($jinzhi)
                {
             case 2:
                                $shu = bindec($zifu);
                $i=strlen($zifu)+1;
                break;
             case 8:
                $shu = octdec($zifu);
                $i=strlen($zifu)+1;
                break;
             case 16:
                $shu = hexdec($zifu);
                                $i=strlen($zifu)+1;
                break;
             case 36:
                if (ord($linshi)<=57)
                {$shu+=(ord($linshi)-48)*pow($jinzhi,strlen($zifu)-$i-1);
                }else{
                  $shu=$shu + (ord($linshi)-55)*pow($jinzhi,strlen($zifu)-$i-1);}
                break;
             case 62:
                if (ord($linshi)<=57)
                {$shu+=$linshi*pow($jinzhi,strlen($zifu)-$i-1);                
                }elseif ((ord($linshi)>=65) && (ord($linshi)<=90)){
                $shu+= (ord($linshi)-55)*pow($jinzhi,strlen($zifu)-$i-1);
                }else{
                $shu+= (ord($linshi)-61)*pow($jinzhi,strlen($zifu)-$i-1);}
                break;
             }
         }
         return $shu;    
        }
         

        /**
         * 10进制高精度转换2、8、16、36、62进制
         *
         * @param unknown_type $shu
         * @param unknown_type $jinzhi
         * @param unknown_type $w
         * @return unknown
         */
         function turnnumric_2($shu,$jinzhi,$w)
         {
         $zifu = "";
         while ($shu!=0){
         $linshi = bcmod($shu,$jinzhi);
         switch ($jinzhi){
             case 2:
                 $zifu = decbin($shu);
                 return $zifu;
               case 8:
                 $zifu = decoct($shu);
                 return $zifu;
             case 16:
                 $zifu = dechex($shu);
                 return $zifu;
             case 36:
                        if ($linshi>=10)
                  {
                  $zifu.= chr(($linshi+55));
                  }else{
                        $zifu.= $linshi;}
                 break;
             case 62:
                  if (($linshi>=10) && ($linshi<36)) {$zifu.= chr($linshi+55);break;}
                  if (($linshi>=36) && ($linshi<62)) {$zifu.= chr($linshi+61);break;}
                  $zifu.= $linshi;break;
         default:
         $zifu.= $linshi;
         break;
         }
         $shu = intval(bcdiv($shu,$jinzhi));
         }
         for ($i=strlen($zifu);$i<$w;$i++)
         $zifu.="0";
        return strrev($zifu);
        }
         

        /**
         * 2、8、16、36、62进制高精度转换10进制
         *
         * @param unknown_type $zifu
         * @param unknown_type $jinzhi
         * @param unknown_type $w
         * @return unknown
         */
    function turnnumric_3($zifu,$jinzhi)
    {    $shu= "";
        for ($i=0;$i<=strlen($zifu)-1;$i++)
                 {
                 $linshi = substr($zifu,$i,1);
                 switch ($jinzhi){
                     case 2:
                         $shu = bindec($zifu);
                         $i=strlen($zifu)+1;
                         break;
                     case 8:
                         $shu = octdec($zifu);
                     $i=strlen($zifu)+1;
                     break;
                     case 16:
                         $shu = hexdec($zifu);
                         $i=strlen($zifu)+1;
                         break;
                    case 36:
                        if (ord($linshi)<=57)
  {$shu=bcadd($shu,bcmul((ord($linshi)-48),bcpow($jinzhi,strlen($zifu)-$i-1)));
                    }else{
                         $shu=bcadd($shu,bcmul((ord($linshi)-55),bcpow($jinzhi,strlen($zifu)-$i-1)));}
                         break;
                    case 62:
                     if (ord($linshi)<=57)
                     {$shu=bcadd($shu,bcmul($linshi,bcpow($jinzhi,strlen($zifu)-$i-1)));
                    }elseif ((ord($linshi)>=65) && (ord($linshi)<=90)){
                     $shu=bcadd($shu,bcmul((ord($linshi)-55),bcpow($jinzhi,strlen($zifu
)-$i-1)));
                     }else{
                     $shu=bcadd($shu,bcmul((ord($linshi)-61),bcpow($jinzhi,strlen($zifu)-$i-1)));
                     }
                     break;
                    }
         }
         return $shu;
    }
}
include 'Snoopy.class.php';
$snoopy = new Snoopy();
$snoopy->referer = "http://login.sina.com.cn/signup/signin.php";
$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 4.0.20506)";
$snoopy->referer = "http://t.sina.com.cn/";
$submit_url = "http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.3.14)";
$submit_vars = array();
$submit_vars['encoding'] = 'utf-8';
$submit_vars['entry']   = 'weibo';
$submit_vars['gateway']   = 1;
$submit_vars['nonce']   = 'M6D9Y1';
$submit_vars['password']   = '91b0929ea39f0d21215782ed41ba5f977ec7254e';
$submit_vars['pwencode']   = 'wsse';
$submit_vars['returntype']   = 'META';
$submit_vars['savestate']   = 0;
$submit_vars['servertime']   = time();
$submit_vars['service']   = 'miniblog';
$submit_vars['ssosimplelogin']   = 1;
$submit_vars['url']   = 'http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack';
$submit_vars['username']   = 'ward.chen@msn.com';
$submit_vars['useticket']   = 1;

$snoopy->submit($submit_url,$submit_vars);
$snoopy->setcookies();
$cookies = $snoopy->cookies;
//$snoopy->fetch('http://i.sso.sina.com.cn/js/ssologin.js;');
//$snoopy->submittext();
$snoopy->fetch('http://weibo.com/wardchen');
$snoopy->maxredirs = 2; 
echo $snoopy->results.'<br/>';
//$url    = "http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.3.14)&encoding=utf-8&entry=weibo&from=&gateway=1&nonce=M6D9Y1&password=91b0929ea39f0d21215782ed41ba5f977ec7254e&pwencode=wsse&returntype=META&savestate=0&servertime=1315381671&service=miniblog&ssosimplelogin=1&url=http%3A%2F%2Fweibo.com%2Fajaxlogin.php%3Fframelogin%3D1%26callback%3Dparent.sinaSSOController.feedBackUrlCallBack&username=ward.chen%40msn.com&useticket=1";

?>
